layui.use(['form', 'table'], function () {
    let $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        layer=layui.layer;
    //form.render();

    managerid = $("[name='managerId']").val();
    if(managerid!==''){
        $.ajax({
            url:bizUrl + '/api/manager/admin/getManagerList',
            type: 'get',
            dataType: 'json',
            data: {managerid:managerid},
            success:function (data) {
                let obj = data.data.list[0];
               // alert(data.data.list[0].userName);
                $("[name='userName']").val(obj.userName);
                $("[name='userAccount']").val(obj.userAccount);
                $("[name='passWord']").val(obj.passWord);
                $("[name='garbageRecyclingComRate']").val(obj.garbageRecyclingComRate);
                $("[name='homeRecyclingComRate']").val(obj.homeRecyclingComRate);
                $("[name='goodsComRate']").val(obj.goodsComRate);
                $("[name='contactName']").val(obj.contactName);
                $("[name='userPhone']").val(obj.userPhone);
                let isFlags = $("[name='isFlag']");
                for (let i=0;i<isFlags.length;i++){
                    if (isFlags[i].value == obj.isFlag) {
                        isFlags[i].setAttribute("checked","true");
                    }
                }
                form.render();
            }
        });
    }

    form.on('submit(saveBtn)',function () {
        $.ajax({
            url:bizUrl + '/api/manager/admin/saveOrUpdateSorting',
            type: 'post',
            dataType: 'json',
            data:{
                managerid:$("[name='managerId']").val(),
                username:$("[name='userName']").val(),
                useraccount:$("[name='userAccount']").val(),
                password:$("[name='passWord']").val(),
                garbagerecyclingcomrate:$("[name='garbageRecyclingComRate']").val(),
                homerecyclingcomrate:$("[name='homeRecyclingComRate']").val(),
                goodscomrate:$("[name='goodsComRate']").val(),
                contactname:$("[name='contactName']").val(),
                userphone:$("[name='userPhone']").val(),
                isflag:$("[name='isFlag']").val()
            },
            success:function (result) {
                alert(result.msg);
                location.href = "sortingList.html";
            }
        })
    });

    $("#remove").click(function () {
        location.href = "sortingList.html";
    })

});